package com.jian.mygame;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

class BodyExtend extends Object {
	private Context mContext = null;
	private int mColorIdx;
	private Drawable mImage;
	private MyAnimation mAnimation;
	private boolean mDrawable;
	private int mSoundID;
	private int mLife;
	private int mDamage;
	private int mScore;
	
	public static final int ROLE_NOTHING = 0;
	public static final int ROLE_BULLET = 1;
	public static final int ROLE_TARGET = 2;
	public static final int ROLE_TOOL = 3;
	public static final int ROLE_STATIC = 4;
	public static final int ROLE_WALL = 5;
	private int mRole;
	
	
	public BodyExtend( Context context ) {
		mColorIdx = Color.RED;
		mImage = null;
		mAnimation = null;
		mDrawable = true;
		mSoundID = 0;
		mRole = ROLE_NOTHING;
		mLife = 100;
		mScore = 0;
		mContext = context;
	}
	
	public BodyExtend(Context context , int colorIdx, boolean isDrawable, int role, Drawable image /*ResourceInfo tool*/, AnimationInfo anima_info, int sound_id  ) {
		this(context );
		
		setColor(colorIdx);
		setDrawable(isDrawable);
		setRole(role);

    	Resources res = mContext.getResources();
        //int imageID = tool.mImageID;
    	//Drawable image = res.getDrawable(imageID);
		
		//bodyextend.setColor(colorIdx);
		setImage(image);
		
		if( anima_info != null){
	        MyAnimation anima = new MyAnimation();
	        anima.Initialize(
							BitmapFactory.decodeResource(res, anima_info.mResID), 
							anima_info.mHeight, anima_info.mWidth, anima_info.mFps, anima_info.mFrameCount);
			setAnimation(anima);
		}
		
		setSoundID(sound_id); 
	}
	
	public void contactedBy( BodyExtend that ){
		switch( mRole ) {
		case ROLE_BULLET:
			if( that.getRole() == ROLE_TARGET ) {
				setLife(0);
				playSound();
			}
			break;
		case ROLE_TARGET:
			if( that.getRole() == ROLE_BULLET ) {
				//mScore = mLife - 0;
				setLife(0);
				playSound();
			}else if( that.getRole() == ROLE_NOTHING ) {
				//setLife(0);
			}
			break;
		
		case ROLE_WALL:
			if( that.getRole() == ROLE_BULLET || that.getRole() == ROLE_TARGET ) {
				//mLife -= 25;
			}
			break;
			
		default:
			break;
		}
	}
	
	protected void playSound() {
		MySound.playSound(getSoundID());
	}
	
	public int getScore(){
		if( getRole() == ROLE_TARGET ) {
			mScore = mLife;
		} else {
			mScore = 0;
		}
		return mScore;
	}
	
	private void setLife( int life ){
		mLife = life;
	}
	
	public int getLife(){
		return mLife;
	}
	
	public void setDamage( int damage ){
		mDamage = damage;
	}
	
	public int getDamage(){
		return mDamage;
	}
	
	public void setDrawable( boolean flag ){
		mDrawable = flag;
	}
	
	public boolean isDrawable(){
		return mDrawable;
	}
	
	public void setRole(int role) {
		mRole = role;
	}
	
	public int getRole() {
		return mRole;
	}
	
	public void setSoundID(int soundid) {
		mSoundID = soundid;
	}
	
	public int getSoundID() {
		return mSoundID;
	}
	
	public void setColor(int colorIdx) {
	    mColorIdx = colorIdx;
	}
	
	public int getColor() {
		return mColorIdx;
	}
	
	public void setImage(Drawable image) {
		mImage = image;
	}
	
	public void setAnimation( MyAnimation anime){
		mAnimation = anime;
	}
	
	
	public Drawable getImage() {
		return mImage;
	}
	
	public MyAnimation getAnimation() {
		return mAnimation;
	}
	
}
